using UnityEngine;
using System.Collections;

public class SkiLauncher : MonoBehaviour {
	
	public KillTrigger killTrigger;
	
	public GameObject fire;
	public GameObject ramp;
	public float launchSpeed;
	public float launchRange;
	
	private float fireTimeCounter;
	private float rampTimeCounter;
	
	// Update is called once per frame
	void Update () {
		if(Controller.inGame)
		{
			fireTimeCounter += Time.deltaTime;
			rampTimeCounter += Time.deltaTime;
			
			if(fireTimeCounter >= Controller.fireLaunchRate)
			{
				Launch(fire);
				fireTimeCounter = 0;
			}
			
			if(rampTimeCounter >= Controller.rampLaunchRate)
			{
				Launch(ramp);
				rampTimeCounter = 0;
			}
		}
	}
	
	private void Launch (GameObject obj)
	{
		GameObject spawnedObj = GameObject.Instantiate(obj, transform.position + new Vector3(Random.Range(-launchRange, launchRange), 0, 2), Quaternion.identity) as GameObject;
		spawnedObj.rigidbody.velocity = Vector3.up * launchSpeed;
		killTrigger.AddToList(spawnedObj);
	}
}
